using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;

public class HintUtil : SingletonMono<HintUtil>
{
    public TextMeshProUGUI tmp;
    public Image mask;
    private IDisposable disposable;

    public void OpenHint(string hintString = "正在生成二维码，请稍候")
    {
        if (disposable != null) CloseHint();

        int count = 0;
     
        tmp.gameObject.SetActive(true);
        mask.gameObject.SetActive(true);

        disposable = Observable.Interval(TimeSpan.FromSeconds(0.5f))
            .Subscribe(x =>
            {
                tmp.text = $"{hintString}{new string('.', count % 4)}";
                count++;
            })
            .AddTo(this);
    }

    public void CloseHint()
    {
        tmp.gameObject.SetActive(false);
        mask.gameObject.SetActive(false);
        disposable.Dispose();
        disposable = null;
    }
}
